import mongoose from "mongoose";

const WikiHouse = mongoose.model("WikiHouse");
const WikiCharacter = mongoose.model("WikiCharacter");

export async function getHouses() {
  const data = await WikiHouse.find({})
    .populate({
      path: "swornMembers.character",
      select: "_id name cname profile"
    })
    .exec();
  return data;
}

export async function getHouse(name) {
  const data = await WikiHouse.findOne({ cname: name })
    .populate({
      path: "swornMember.character",
      select: "_id name cname profile"
    })
    .exec();

  return data;
}

export async function getCharacters(page,count) {
  let skip = (page - 1) * count;
  const data = await WikiCharacter.find({})
    .limit(count)
    .skip(skip)
    .exec();

  return data;
}

export async function getCharacter(_id) {
  const data = await WikiCharacter.findOne({ _id }).exec();
  return data;
}
